import {createWebHashHistory, createRouter} from 'vue-router'

/* Layout */
import Layout from '../views/layout/Layout.vue'
import store from '../store';

const routes = [
  {
    path: '/',
    name: 'Login',
    component: ()=>import('../views/Login.vue')
  },
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/index',
  //   name: '首页',
  //   children: [{
  //       path: 'index',
  //       name: '首页',
  //       meta: { title: '首页' },
  //       component: ()=>import('../views/Index.vue')
  //   }]
  // },
  {
    path: '/',
    component: Layout,
    redirect: '/torrent',
    children: [{
        path: '/torrent',
        name: 'torrent',
        meta: { title: '种子管理' },
        component: ()=>import('../views/Torrent/Torrent.vue')
    }]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/client',
    children: [{
        path: '/client',
        name: 'client',
        meta: { title: '下载器' },
        component: ()=>import('../views/Client/Client.vue')
    }]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/btsite',
    children: [{
        path: '/btsite',
        name: 'btsite',
        meta: { title: '站点配置' },
        component: ()=>import('../views/BTSite/BTSite.vue')
    }]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/category',
    children: [{
        path: '/category',
        name: 'category',
        meta: { title: '分类配置' },
        component: ()=>import('../views/Category/Category.vue')
    }]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/library',
    children: [{
        path: '/library',
        name: 'library',
        meta: { title: '媒体库' },
        component: ()=>import('../views/Library/Library.vue')
    }]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/config',
    children: [{
        path: '/config',
        name: 'config',
        meta: { title: '基础配置' },
        component: ()=>import('../views/Config/Config.vue')
    }]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/about',
    children: [{
        path: '/about',
        name: 'about',
        meta: { title: '关于' },
        component: ()=>import('../views/About.vue')
    }]
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((guard) => {
  // console.info('router.beforeEach:', guard)
  if (guard.path != '/' && !store.state.authed) {
    router.replace({
      path: "/"
    });
  }
});
router.onError((handler) => {
	console.log("error:", handler);
});

export default router
